/*=========================================================================
 
Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date: 2010-01-29 01:32:03 +0800 (周五, 29 一月 2010) $
Version:   $Revision: 21147 $
 
Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.
 
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.
 
=========================================================================*/

#ifndef MITKMITKLABELEDIMAGELOOKUPTABLE_H
#define MITKMITKLABELEDIMAGELOOKUPTABLE_H

#include "mitkLookupTable.h"
#include "MitkExtExports.h"
#include "mitkLevelWindow.h"
#include <iostream>
#include <string>

namespace mitk
{

/** 
 * A lookup table for 2D mapping of labeled images. The lookup table supports
 * images with up to 256 unsigned labels. Negative labels are not supported.
 * Please use the level/window settings as given by the GetLevelWindow() method
 * to make sure, that the colors are rendered correctly. 
 * The colors are initialized with random colors as default. As background 
 * the label 0 is assumed. The color for the background is set to fully transparent
 * as default.
 */
class MitkExt_EXPORT LabeledImageLookupTable : public LookupTable
{
public:
  /** 
   * Standard mitk typedefs are generated by the mitkClassMacro
   */
  mitkClassMacro(LabeledImageLookupTable, LookupTable);
  
  /**
   * Make this object constructable by the ::New() Method.
   */
  itkNewMacro(Self);
  
  /**
   * The data type for a label. Currently only images with labels
   * in the range [0,255] are supported.
   */
  typedef unsigned char LabelType;
  
  /**
   * Sets the color for a given label
   * @param label The pixel value used as a label in the image
   * @param r The red component of the rgba color value. Values sould be given in the range [0,1]
   * @param g The green component of the rgba color value. Values sould be given in the range [0,1] 
   * @param b The blue component of the rgba color value. Values sould be given in the range [0,1]
   * @param a The alpha component of the rgba color value. Values sould be given in the range [0,1]. Default is 1.
   */
  virtual void SetColorForLabel( const LabelType& label, const vtkFloatingPointType& r, const vtkFloatingPointType& g, const vtkFloatingPointType& b, const vtkFloatingPointType a = 1.0 );
  
  /**
   * Determines the color which will be used for coloring a given label.
   * @param label the label for which the color should be returned
   * @returns an rgba array containing the color information for the given label. 
   *          Color components are expressed as [0,1] double values.
   */
  virtual vtkFloatingPointType* GetColorForLabel(const LabelType& label);
  
  /**
   * Provides access to level window settings, which should be used
   * in combination with the LUTs generated by this filter (at lease for
   * 2D visualization. If you use other level/window settings, it is not 
   * guaranteed, that scalar values are mapped to the correct colors.
   */
  mitk::LevelWindow GetLevelWindow(){return m_LevelWindow;}
  
protected:
  /** 
   * Default constructor. Protected to prevent "normal" creation
   */
  LabeledImageLookupTable();
  
  /** 
   * Virtual destructor
   */
  virtual ~LabeledImageLookupTable();    
  
  /**
   * Generates a random rgb color value. Values for rgb are in the range
   * [0,1]
   */
  virtual void GenerateRandomColor( vtkFloatingPointType& r, vtkFloatingPointType& g, vtkFloatingPointType& b);
  /**
   * Generates a radnom number drawn from a uniform
   * distribution in the range [0,1].
   */
  virtual vtkFloatingPointType GenerateRandomNumber();
  

  mitk::LevelWindow m_LevelWindow;
};

}

#endif
